/*
 * AdvancedTimer.java
 *
 * Created on 7 de mayo de 2006, 12:59 AM
 */

package taladro.control;

import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;

import com.dnsalias.java.timer.AdvancedTimer;

import controles.interfaz.Consola;

/**
 *
 * @author Administrator
 */
public class SystemTimer {
    
    /** Our link into the GAGE timer library */
    private static AdvancedTimer timer = new AdvancedTimer();
    /** The number of "timer ticks" per second */
    private static long timerTicksPerSecond;
    
    /** A little initialisation at startup, we're just going to get the GAGE timer going */
    static {
        timer.start();
        timerTicksPerSecond = AdvancedTimer.getTicksPerSecond();
        System.out.println("Ticks per second " + timerTicksPerSecond);
    }
    
    /**
     * Get the high resolution time in milliseconds
     *
     * @return The high resolution time in milliseconds
     */
    public static long getTime() {
        // we get the "timer ticks" from the high resolution timer
        // multiply by 1000 so our end result is in milliseconds
        // then divide by the number of ticks in a second giving
        // us a nice clear time in milliseconds
        return (timer.getClockTicks() * 1000) / timerTicksPerSecond;
    }
    
    /**
     * Sleep for a fixed number of milliseconds.
     *
     * @param duration The amount of time in milliseconds to sleep for
     */
    public static void sleep(long duration) {
        timer.sleep((duration * timerTicksPerSecond) / 1000);
    }
    
    public static void sleep(double duration) {
        timer.sleep((long)(duration * timerTicksPerSecond) / 1000);
    }

    
}
